package gof_003_行为型_Behavioral.gof_004_策略_Strategy.gof_002_Strategy;

import java.util.ArrayList;
import java.util.List;

public class FilterStudent {
    //策略
    private Strategy strategy;
    //创建的时候
    public FilterStudent(Strategy strategy) {
        this.strategy = strategy;
    }

    public  List<Student> filter(List<Student> studentList) {
        //创建一个list集合用来保存学生
        List<Student> list = new ArrayList<>();

        //遍历学生列表
        for (int i = 0; i < studentList.size(); i++) {
            Student student = studentList.get(i);

            //如果学生的年龄大于 20 岁
            if (strategy.condition(student)) {
                list.add(student);
            }
        }
        return list;
    }
}
